/*
 * Copyright (c) 2004-2005 Endace Technology Ltd, Hamilton, New Zealand.
 * All rights reserved.
 *
 * This source code is proprietary to Endace Technology Ltd and no part
 * of it may be redistributed, published or disclosed except as outlined
 * in the written contract supplied with this product.
 *
 * $Id: dagclarg.h,v 1.6 2006-06-01 05:50:28 sashan Exp $
 */
 
/* Integrated CommandLine ARGument processing (i.e. getopt_long()) and usage(). */

#ifndef DAGCLARG_H
#define DAGCLARG_H

/* Endace headers. */
#include "dagutil.h"


typedef struct ClArg_ ClArg_;
typedef ClArg_* ClArgPtr; /* Opaque type-safe pointer. */


#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */


/* Lifecycle routines. */
ClArgPtr dagclarg_init(int argc, const char* const * argv);
ClArgPtr dagclarg_dispose(ClArgPtr clarg);

/* Add an option. */
void dagclarg_add(ClArgPtr clarg, const char* description, const char* longopt, const char shortopt, uint16_t code);
void dagclarg_add_char(ClArgPtr clarg, const char* description, const char* longopt, const char shortopt, const char* argname, uint8_t* storage, uint16_t code);
void dagclarg_add_int(ClArgPtr clarg, const char* description, const char* longopt, const char shortopt, const char* argname, int32_t* storage, uint16_t code);
void dagclarg_add_uint(ClArgPtr clarg, const char* description, const char* longopt, const char shortopt, const char* argname, uint32_t* storage, uint16_t code);
void dagclarg_add_string(ClArgPtr clarg, const char* description, const char* longopt, const char shortopt, const char* argname, char* buffer, uint32_t buflen, uint16_t code);

/* Add properties to an existing option. */
void dagclarg_add_short_option(ClArgPtr clarg, uint16_t code, const char shortopt);
void dagclarg_add_long_option(ClArgPtr clarg, uint16_t code, const char* longopt);
void dagclarg_add_description(ClArgPtr clarg, uint16_t code, const char* line);
void dagclarg_suppress_display(ClArgPtr clarg, uint16_t code);


/* Parse commandline arguments: 1 = valid, 0 = no more commands, -1 = error parsing option argument (ie missing). 
 * If an unrecognised option is found, it is added to the unprocessed args array and the code
 * argument to dagclarg_parse() will contain -1 on output.
 */
int dagclarg_parse(ClArgPtr clarg, FILE* errorfile, int* argindex, int* code);

/* Returns an {argc, argv} pair containing the commandline arguments that were unrecognised. */
char** dagclarg_get_unprocessed_args(ClArgPtr clarg, int* unprocessed_argc);

/* Display autogenerated usage text. */
void dagclarg_display_usage(ClArgPtr clarg, FILE* outfile);

/* Reset the internal argument counters so one can use dagclarg_parse repeatedly from the beginning again */
void dagclarg_reset(ClArgPtr clarg);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* DAGCLARG_H */
